package handler

import (
	"database/sql"

	"gitee.com/hp-huiw/family-expense-api/internal/service"
	"github.com/gin-gonic/gin"
)

type BankHandler interface {
	QueryAllWithBasicInfo(ctx *gin.Context)
}

func NewBankHandler(db *sql.DB) BankHandler {
	return &bankHandler{
		bankService: service.NewBankService(db),
	}
}

// Matches /queryAllWithBasicInfo of http get action.
func (h *bankHandler) QueryAllWithBasicInfo(ctx *gin.Context) {
	c := ctx.Request.Context()
	result, err := h.bankService.QueryAllWithBasicInfo(c)

	if err != nil {
		ctx.Error(err)
		return
	}

	SendDataResponse(ctx, result)
}

// Container of BankHandler functions.
type bankHandler struct {
	bankService service.BankService
}
